package org.rency.spring.cloud.boot.mvc.customer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.ErrorViewResolver;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 定制错误处理页面
 *
 * @author: Created by user_rcy@163.com on 2016/8/19.
 * @version: V1.0.0
 * @since JDK 1.8
 */
@Component
public class CustomerErrorViewResolver implements ErrorViewResolver{

    private static final Logger logger = LoggerFactory.getLogger(CustomerErrorViewResolver.class);

    public ModelAndView resolveErrorView(HttpServletRequest httpServletRequest, HttpStatus httpStatus, Map<String, Object> map) {
        int httpCode = httpStatus.value();
        String viewName = "error/"+String.valueOf(httpCode).substring(0,1)+"xx";
        ModelAndView mv = new ModelAndView(viewName,map,httpStatus);
        logger.info("视图解析发生未知异常,{}",mv);
        return mv;
    }
}
